package DataBase;

import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.mysql.jdbc.ResultSet;

public class CheckScheduleIfExists {
	
	private String name ;	
	private int result;
	
	public CheckScheduleIfExists (String name)
	{
		this.name=name;
	}

	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getResult() {
		return result;
	}

	public void setResult(int result) {
		this.result = result;
	}
	
	
	public void check()
	{
		SQLConnection sc=new SQLConnection();
		try {
			PreparedStatement ps1 = sc.getConnection().prepareStatement("SELECT scheduleName FROM schedule WHERE scheduleName=? ;");
			PreparedStatement ps2 = sc.getConnection().prepareStatement("INSERT INTO schedule(scheduleName) values(?);");
			ps1.setString(1, name);
			ResultSet rs=(ResultSet) ps1.executeQuery();	
			if (rs.next())
			{
				
			result=1;	
			
			}
			else
			{				
				result=0;
				ps2.setString(1, name);
				ps2.executeUpdate();

				result=0;
			}
			rs.close();
			ps1.close();
			 sc.getConnection().close();
		} 
		
		catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
